// JS 代码
$(function() {
    Highcharts.setOptions({
        lang: {
            rangeSelectorZoom: ''
        }
    });
    var superid = window.localStorage.getItem("super_id");
    var to = window.localStorage.getItem("super_id");

    function refresh() {
        $.getJSON(
            'http://119.23.224.92/jiandao/startTransaction/page', { "starId": superid },
            function(data) {
                var al = data.data,
                    aa = al.todayOrder,
                    tot = al.token;
                var ohlc = [],
                    volume = [],
                    dataLength = aa.length,
                    i = 0;

                for (i; i < dataLength; i += 1) {

                    ohlc.push([
                        aa[i]['createtime'], // the date
                        aa[i]['sellprice'],
                    ]);
                    volume.push([
                        aa[i]['createtime'], // the date
                        aa[i]['count'] // the volume
                    ]);
                }
                $.ajax({
                        type: 'post',
                        url: 'http://119.23.224.92/jiandao/transaction/polling',
                        data: {
                            starId: superid,
                            token: tot
                        },
                        success: function(data) {
                            var ll = JSON.parse(data),
                                lt = ll.data.isRefresh;
                            if (lt == 1) {
                                refresh();
                            } else {
                                return false;
                            }

                        },
                        error: function(data) {
                            conwarn.log(2)
                        }
                    })
                    // create the chart
                $('#container').highcharts('StockChart', {
                    rangeSelector: {
                        enabled: false,
                        inputDateFormat: '%H:%M'
                    },
                    title: {
                        text: '数据测试'
                    },
                    xAxis: {
                        dateTimeLabelFormats: {
                            millisecond: '%H:%M:%S.%L',
                            second: '%H:%M:%S',
                            minute: '%H:%M',
                            hour: '%H:%M',
                            day: '%m-%d',
                            week: '%m-%d',
                            month: '%y-%m',
                            year: '%Y'
                        }
                    },
                    yAxis: [{
                        labels: {
                            align: 'right',
                            x: -3
                        },
                        title: {
                            text: '股价'
                        },
                        height: '60%',
                        lineWidth: 2
                    }, {
                        labels: {
                            align: 'right',
                            x: -3
                        },
                        title: {
                            text: '成交量'
                        },
                        top: '65%',
                        height: '35%',
                        offset: 0,
                        lineWidth: 2
                    }],
                    series: [{
                        type: 'line',
                        name: 'AAPL',
                        data: ohlc
                    }, {
                        type: 'column',
                        name: 'Volume',
                        data: volume,
                        yAxis: 1
                    }]
                });

                $('#container1').highcharts('StockChart', {
                    rangeSelector: {
                        selected: 1,
                        inputDateFormat: '%Y-%m-%d'
                    },
                    title: {
                        text: ''
                    },
                    xAxis: {
                        dateTimeLabelFormats: {
                            millisecond: '%H:%M:%S.%L',
                            second: '%H:%M:%S',
                            minute: '%H:%M',
                            hour: '%H:%M',
                            day: '%m-%d',
                            week: '%m-%d',
                            month: '%y-%m',
                            year: '%Y'
                        }
                    },
                    yAxis: [{
                        labels: {
                            align: 'right',
                            x: -3
                        },
                        title: {
                            text: '股价'
                        },
                        height: '60%',
                        lineWidth: 2
                    }, {
                        labels: {
                            align: 'right',
                            x: -3
                        },
                        title: {
                            text: '成交量'
                        },
                        top: '65%',
                        height: '35%',
                        offset: 0,
                        lineWidth: 2
                    }],
                    series: [{
                        type: 'line',
                        name: 'AAPL',
                        data: ohlc
                    }, {
                        type: 'column',
                        name: 'Volume',
                        data: volume,
                        yAxis: 1
                    }]
                });
            });
    }
    refresh();
});